#ifndef _LINKED_LIST_MSG_H_
#define _LINKED_LIST_MSG_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "protocol.h"

typedef struct {
    Header hdr;
    char msg_text [MAX_MSG_LEN];
} Message;

typedef struct Message_Cell *MessagePointer;

typedef struct Message_Cell {
	Message msg;
	MessagePointer next;
} MessageCell;

typedef struct {
	MessagePointer first;//, last;
	MessagePointer lastCellInOrder;
} MessageList;

void start_list (MessageList* list);

int isEmpty (MessageList* list);

Message* getMessage (unsigned short int  id, char* orig_id, MessageList* list);

Message* getNextMessage (unsigned short int  id, char* orig_id, MessageList* list);

MessagePointer insert (char* msg_text, Header* hdr, MessageList* list, MessagePointer after);

/*this function insert in order and return 1 if is completely in order, and 0 otherwise
  the parameter lastHdr is used to return the last header  */
int insertInOrder (char* msg_text, Header* hdr, MessageList* list, Header* lastHdr);

void printList (MessageList* list);

#endif /* _LINKED_LIST_MSG_H_ */
